<!DOCTYPE html>
<html>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a>首页管理</a>
        <a><cite>首页列表</cite></a>
    </div>
</div>

<body>

    <div class="layui-card-body">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>首页列表信息</legend>
        </fieldset>
        <table class="layui-hide" id="table-instance" lay-filter="table-instance"></table>

        <script type="text/html" id="table-useradmin-admin">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        </script>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>常规轮播</legend>
    </fieldset>
    <div class="layui-carousel" id="test1" lay-filter="test1">
        <div carousel-item id="demo1">
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>首页视频</legend>
    </fieldset>
    <div id="video1">

    </div>


    <script>
        layui.use(['carousel', 'form', 'admin', 'element', 'useradmin', 'table', 'laydate', 'layedit'], function() {
            var carousel = layui.carousel,
                $ = layui.$,
                setter = layui.setter,
                view = layui.view,
                table = layui.table,
                form = layui.form,
                elem = layui.element,
                admin = layui.admin,
                laydate = layui.laydate,
                layedit = layui.layedit;

            var video = "";

            //常规轮播
            var tar = carousel.render({
                elem: '#test1',
                arrow: 'always'
            });

            //获取轮播图
            admin.req({
                url: setter.request.baseUrl + "/aboutus/admin/imgs",
                type: "get",
                done: function(res) {
                    var piclist = res.list; //返回参数名

                    for (var i in piclist) {
                        var str = '<div><img src=' + piclist[i] + '></div>';
                        $('#demo1').append(str);
                    }
                    tar.reload({
                        elem: '#test1',
                        width: '100%' //设置容器宽度
                            ,
                        arrow: 'always' //始终显示箭头
                            //,anim: 'updown' //切换动画方式
                    });
                },
            });

            table.render({
                elem: "#table-logo", //表id
                url: setter.request.baseUrl + "/logo/admin/logo",
                method: "get",
                headers: {
                    token: layui.data("layuiAdmin").token
                },
                response: {
                    statusName: "code",
                    statusCode: 0,
                    msgName: "msg",
                    countName: "count",
                    dataName: "list",
                },
                cols: [
                    [{
                        field: "logoId",
                        width: "5%",
                        sort: true
                    }, {
                        field: "pageTop",
                        title: "页面顶部"
                    }, {
                        field: "topLogo",
                        title: "顶部logo"
                    }, {
                        field: "bottomLogo",
                        title: "底部logo"
                    }, {
                        field: "name",
                        title: "公司名称"
                    }, {
                        field: "recordNo",
                        title: "备案号"
                    }, {
                        field: "address",
                        title: "公司地址"
                    }, {
                        field: "englishAddr",
                        title: "英文地址"
                    }, {
                        field: "phone",
                        title: "电话"
                    }, {
                        field: "email",
                        title: "邮箱地址"
                    }, {
                        field: "codeImg",
                        title: "二维码"
                    }, {
                        fixed: "right",
                        title: "操作",
                        toolbar: "#table-useradmin-admin",
                        width: 150
                    }, ],
                ],
                page: false,
            });


            table.render({
                elem: "#table-instance", //表id
                url: setter.request.baseUrl + "/aboutus/admin/list",
                method: "get",
                headers: {
                    token: layui.data("layuiAdmin").token
                },
                response: {
                    statusName: "code",
                    statusCode: 0,
                    msgName: "msg",
                    countName: "count",
                    dataName: "list",
                },
                cols: [
                    [{
                            field: "id",
                            width: "5%",
                            title: "ID",
                            sort: true
                        }, {
                            field: "rotationImgs",
                            width: "5%",
                            title: "轮播图",
                            sort: true
                        }, {
                            field: "title",
                            title: "标题"
                        }, {
                            field: "content",
                            title: "关于我们内容"
                        }, {
                            field: "videoUrl",
                            title: "视频连接"
                        }, {
                            field: "createYear",
                            title: "成立年份"
                        }, {
                            field: "solutionNum",
                            title: "解决方案数量"
                        }, {
                            field: "partnerNum",
                            title: "合作单位数量"
                        }, {
                            field: "landSquare",
                            title: "占地"
                        },

                        // templet:"#Sex"
                        {
                            fixed: "right",
                            title: "操作",
                            toolbar: "#table-useradmin-admin",
                            width: 150
                        },
                    ],
                ],
                done: function(res) {
                    var html
                    var url = res.list[0].videoUrl;
                    html = '<video width="100%" height="98%" controls autoplay>'
                    html += '<source src=' + url + '>'
                    html += '</video>'
                    $('#video1').append(html);

                },
                page: false,
            });

            //修改模块
            table.on("tool(table-instance)", function(obj) {
                var data = obj.data;

                if (obj.event === "edit") {
                    admin.popup({
                        title: "编辑用户",
                        area: ["800px", "900px"],
                        success: function(layero, index) {

                            view(this.id)
                                .render("/countpoint/countpointform", data)
                                .done(function() {
                                    let _data = data;
                                    form.render(null, "layuiadmin-app-form-list");

                                    layedit.set({
                                        uploadImage: {
                                            url: setter.request.baseUrl + "/upload/admin/file",
                                            type: 'post'
                                        }
                                    });

                                    var aa = layedit.build('demo', {
                                        width: 600
                                    });
                                    console.log(1111)

                                    layedit.setContent(aa, _data.content, false)

                                    form.on("submit(LAY-user-front-submit)", function(data) {


                                        var field = data.field;

                                        console.log(field);

                                        // editUserHandle(Object.assign(_data, field));

                                        layer.close(index);
                                    });
                                });
                        },
                    });
                }
            });

            //编辑
            function editUserHandle(params) {
                console.log(params)

                //  debugger
                admin.req({
                    //*****************需要替换****************
                    url: setter.request.baseUrl + "/aboutus/admin/save",
                    data: {
                        ...params,
                    },
                    type: "post",
                    done: function(res) {
                        layer.msg(res.msg);
                    },
                });
            }

        });

        layui.$('.layui-btn.layuiadmin-btn-admin').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    </script>

</body>

</html>
<!-- <script>
    layui.use('useradmin', layui.factory('useradmin')).use(['admin', 'useradmin', 'table', 'laydate'], function () {
        var $ = layui.$
            , admin = layui.admin
            , setter = layui.setter
            , view = layui.view
            , table = layui.table
            , form = layui.form
            , laydate = layui.laydate;

        form.render(null, 'layadmin-useradmin-formlist');

        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('table-instance', {
                where: field
            });
        });


        //修改模块
        table.on("tool(table-instance)", function (obj) {
            var data = obj.data;

            if (obj.event === "del") {
                layer.confirm("真的删除么", function (index) {
                    delAdminHandle({
                        orderFormId: data.orderFormId,
                    });

                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === "edit") {
                admin.popup({
                    title: "编辑用户",
                    area: ["500px", "500px"],
                    success: function (layero, index) {

                        view(this.id)
                            .render("orderform/orderform", data)
                            .done(function () {
                                let _data = data;
                                form.render(null, "layuiadmin-form-admin");

                                form.on("submit(LAY-user-front-submit)", function (data) {

                                    var field = data.field;

                                    editUserHandle(Object.assign(_data, field));

                                    layer.close(index);
                                });
                            });
                    },
                });
            }
        });

        

        $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script> -->